package com.camunda.workflow.camunda;

import com.camunda.workflow.mapper.*;
import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration;
import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration;
import org.camunda.bpm.spring.boot.starter.util.CamundaSpringBootUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CamundaConfig {
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Autowired
    private SysTenantMapper sysTenantMapper;
    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;
    @Autowired
    private SysTenantUserRoleMapper sysTenantUserRoleMapper;

    @Bean
    public ProcessEngineConfiguration processEngineConfiguration() {
        // 创建并配置ProcessEngineConfiguration
        SpringProcessEngineConfiguration config = CamundaSpringBootUtil.springProcessEngineConfiguration();
        config.setIdentityProviderSessionFactory(identityProviderFactory());
        return config;
    }

    @Bean
    public CustomIdentityProviderFactory identityProviderFactory() {
        return new CustomIdentityProviderFactory(sysUserMapper, sysRoleMapper, sysTenantMapper, sysUserRoleMapper, sysTenantUserRoleMapper);
    }
}
